package com.example.qing.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Dict;
import com.example.qing.pojo.Emp;
import com.example.qing.pojo.Result;
import com.example.qing.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
@CrossOrigin
public class UploadController {

    @Autowired
    AliOSSUtils aliOSSUtils;

    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws IOException {
        log.info("文件上传");

        String url= aliOSSUtils.upload(file);

        return Result.success(url);
    }

    @PostMapping("/editor/upload")
    public Dict editorUpload(MultipartFile file) throws IOException {
        log.info("文件上传");

        String url= aliOSSUtils.upload(file);
        Dict dict=Dict.create().set("errno",0).set("data", CollUtil.newArrayList(Dict.create().set("url",url)));

        return dict;
    }

}
